﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;

namespace Gunny
{
    public partial class Form1 : Form
    {


        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private string BASE64_CHARS ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
        
        public byte[] DecodeToByteArray(string s)
        { 
            byte[] result = null;
            int[] loc2 = null;
            int[] loc3 = null;
            int pos = 0;
            int i = 0;
            int j = 0;
            result = new byte[1000];
            loc2 = new int[4];
            loc3 = new int[3];
            pos = 0;
            while (pos < s.Length) 
            {
                i = 0;
                while (i < 4 && pos + i < s.Length) 
                {
                    loc2[i] = BASE64_CHARS[s[pos + i]];
                    ++i;
                }
                loc3[0] = (loc2[0] << 2) + ((loc2[1] & 48) >> 4);
                loc3[1] = ((loc2[1] & 15) << 4) + ((loc2[2] & 60) >> 2);
                loc3[2] = ((loc2[2] & 3) << 6) + loc2[3];
                j = 0;
                while (j < loc3.Length) 
                {
                    if (loc2[j + 1] == 64) 
                    {
                        break;
                    }
                    result.writeByte(loc3[j]);
                    ++j;
                }
                pos = pos + 4;
            }
            result.position = 0;
            return result;
        }
    }
}
